package com.hzsai.service.Impl;

import com.github.pagehelper.PageHelper;
import com.hzsai.dto.UserDTO;
import com.hzsai.mappersa.UserMapper;
import com.hzsai.pojo.User;
import com.hzsai.service.MyBatisUserService;
import com.hzsai.utils.ResponseMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * hzsai 2019/8/12
 * usage:
 **/
@Slf4j
@Service
public class MyBatisUserServiceImpl implements MyBatisUserService {

    private UserMapper mapper;

    PageHelper pageHelper;

    @Autowired
    public MyBatisUserServiceImpl(UserMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public Map getUserById(long id) {
        return mapper.getUserById(id);
    }

    @Override
    public ResponseMsg insertUser(UserDTO user) {
        mapper.insertUser(user);
        return ResponseMsg.success();
    }

    @Override
    public List<User> getPageUser(long id, long size) {
        List<User> users = mapper.getPageUser(id, size);
        log.info(users.toString());
        return users;
    }

    @Override
    public User getUserByNameAndId(long id, String name) {
        User user = mapper.getUserByNameAndId(id, name);
        return user;
    }
}
